package com.sun.audit.config;

import com.sun.audit.intercept.AuditLogInterceptor;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author pytho
 */
public class MyBatisInterceptorConfig {

    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource,
                                                   AuditLogInterceptor auditLogInterceptor) throws Exception {
        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
        factory.setDataSource(dataSource);
        // 添加拦截器
        factory.setPlugins(auditLogInterceptor);
        return factory;
    }
}